package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportPurchaseInventoryDetail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2021-02-24 15:59:50
 */
@Repository
public class TransportPurchaseInventoryDetailDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportPurchaseInventoryDetailDao.class);

    public TransportPurchaseInventoryDetail insert(final TransportPurchaseInventoryDetail transportPurchaseInventoryDetail) {
        insert("TransportPurchaseInventoryDetail.insert", transportPurchaseInventoryDetail);
        return transportPurchaseInventoryDetail;
    }

    public Boolean updateInfoById(final TransportPurchaseInventoryDetail transportPurchaseInventoryDetail) {
        return update("TransportPurchaseInventoryDetail.updateInfoById", transportPurchaseInventoryDetail) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportPurchaseInventoryDetail.updateInfoByQuery", query) > 0;
    }

    public TransportPurchaseInventoryDetail selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("TransportPurchaseInventoryDetail.selectById", query);
    }

    public List<TransportPurchaseInventoryDetail> selectByQuery(final Query query) {
        return queryForList("TransportPurchaseInventoryDetail.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportPurchaseInventoryDetail.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        TransportPurchaseInventoryDetail transportPurchaseInventoryDetail = new TransportPurchaseInventoryDetail();
        transportPurchaseInventoryDetail.setDeleteFlag(1);
        transportPurchaseInventoryDetail.setId(id);
        transportPurchaseInventoryDetail.setEntId(entId);

        return update("TransportPurchaseInventoryDetail.updateInfoById", transportPurchaseInventoryDetail) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportPurchaseInventoryDetail.deleteById", query) > 0;
    }
}